package com.ruoyi.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTender;
import com.ruoyi.system.service.ISysTenderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 招标信息Controller
 * 
 * @author ruoyi
 * @date 2025-08-27
 */
@RestController
@RequestMapping("/system/tender")
public class SysTenderController extends BaseController
{
    @Autowired
    private ISysTenderService sysTenderService;

    /**
     * 查询招标信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:tender:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTender sysTender)
    {
        startPage();
        List<SysTender> list = sysTenderService.selectSysTenderList(sysTender);
        return getDataTable(list);
    }

    /**
     * 导出招标信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:tender:export')")
    @Log(title = "招标信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysTender sysTender)
    {
        List<SysTender> list = sysTenderService.selectSysTenderList(sysTender);
        ExcelUtil<SysTender> util = new ExcelUtil<SysTender>(SysTender.class);
        util.exportExcel(response, list, "招标信息数据");
    }

    /**
     * 获取招标信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tender:query')")
    @GetMapping(value = "/{tenderId}")
    public AjaxResult getInfo(@PathVariable("tenderId") Long tenderId)
    {
        return success(sysTenderService.selectSysTenderByTenderId(tenderId));
    }

    /**
     * 新增招标信息
     */
    @PreAuthorize("@ss.hasPermi('system:tender:add')")
    @Log(title = "招标信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTender sysTender)
    {
        return toAjax(sysTenderService.insertSysTender(sysTender));
    }

    /**
     * 修改招标信息
     */
    @PreAuthorize("@ss.hasPermi('system:tender:edit')")
    @Log(title = "招标信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTender sysTender)
    {
        return toAjax(sysTenderService.updateSysTender(sysTender));
    }

    /**
     * 删除招标信息
     */
    @PreAuthorize("@ss.hasPermi('system:tender:remove')")
    @Log(title = "招标信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tenderIds}")
    public AjaxResult remove(@PathVariable Long[] tenderIds)
    {
        return toAjax(sysTenderService.deleteSysTenderByTenderIds(tenderIds));
    }

    /**
     * 下拉框
     */
    @PostMapping("/list_selects")
    public AjaxResult listSelects(){
        return sysTenderService.listSelects();
    }

}
